Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix] handle null prototype objects #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

magicmark
Copy link

@mcmath thanks for this library!

Came across an issue we're hitting - if this library called over any objects created with Object.create(null), then an error is thrown because of this line:

if (obj.hasOwnProperty(key)) {

I've added a regression test, which also demonstrates the issue:

before

$ npm run test:unit

> [email protected] test:unit
> istanbul cover -e .ts -x '*.test.ts' _mocha -- src --opts mocha.opts

  !․․․․․․․․․․․․․

  13 passing (39ms)
  1 failing

  1) handles null prototype objects:
     TypeError: obj.hasOwnProperty is not a function
      at DeepMapKeys.mapObject (src/deep-map-keys.ts:1:6130)
      at DeepMapKeys.map (src/deep-map-keys.ts:1:5022)
      at deepMapKeys (src/index.ts:1:3000)
      at Context.<anonymous> (src/index.test.ts:112:3)
      at processImmediate (node:internal/timers:471:21)

after

it passes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant